package com.yanqu.road.server.cmd.activity.curio;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cangbao.CurioProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.manger.activity.curio.CurioMgr;
import com.yanqu.road.server.protocol.Protocol;
import io.netty.channel.ChannelHandlerContext;

import java.math.BigInteger;
import java.util.HashMap;

@Cmd(code = Protocol.S_CURIO_MAX_SCORE_SYNC_FROM_CROSS, desc = "藏品最高分数同步")
public class CurioMaxScoreSyncFromCrossCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage yanQuMessage) throws Exception {
        CurioProto.CrossCurioMaxScoreSyncMsg scoreSyncMsg = CurioProto.CrossCurioMaxScoreSyncMsg.parseFrom(yanQuMessage.getBytes());
        HashMap<Integer, BigInteger> scoreMap = new HashMap<>();
        for (CurioProto.CrossCurioMaxScoreTemp scoreTemp : scoreSyncMsg.getItemScoreList()) {
            scoreMap.put(scoreTemp.getCurioItemId(), BigInteger.valueOf(scoreTemp.getScore()));
        }
        CurioMgr.updateMaxScore(scoreMap, scoreSyncMsg.hasAllSync() ? scoreSyncMsg.getAllSync() : false);
    }
}
